package P001;

import org.junit.Test;

/**
 * @Author DJ同学
 * @Date 2021/2/7 12:50
 * @Version 1.0
 * @Name 两数之和
 * @Problem https://leetcode-cn.com/problems/two-sum/
 */
 class Solution {
    @Test
     void test(){
//        int[] nums ={2,7,11,15};
        int[] nums ={3,2,4};

        int[] indexs = twoSum(nums,6);
        System.out.println(indexs[0]);
        System.out.println(indexs[1]);
    }
    public int[] twoSum(int[] nums, int target) {
        int f = 0;
        int[] indexs = new int[2];
        for(int i = 0;i<nums.length;i++){
            for(int j = i+1;j<nums.length;j++){
                if(nums[i]+nums[j]==target){
                    indexs[0]=i;
                    indexs[1]=j;
                    f=1;
                    break;
                }
            }
            if(f==1) break;
        }
        return indexs;
    }
}
